package com.gxa.order.service.impl;/*
 *Created by${妄也} on 2022/10/9
 */

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.gxa.common.commons.JsonResult;
import com.gxa.common.commons.R;
import com.gxa.order.mapper.BannerMapper;
import com.gxa.order.pojo.Bannerb;
import com.gxa.order.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class BannerServiceImpl implements BannerService {
    @Autowired(required = false)
    private BannerMapper bannerMapper;
    @Override
    public JsonResult findbanner(HashMap map) {
        JsonResult pageResult = new JsonResult();
//        分页操作
        Integer currentPage = Integer.parseInt(map.get("currentPage").toString());
        Integer pageSize = Integer.parseInt(map.get("pageSize").toString());
        int current = (currentPage-1)*pageSize;
        System.out.println(current);
        map.put("currentPage",current);
        map.put("pageSize",pageSize);
        List<Bannerb> findbanner = bannerMapper.findbanner(map);
        Integer findcount = bannerMapper.findcount(map);
        pageResult.setCode(200);
        pageResult.setMsg("查询成功");
        pageResult.setCount(findcount);
        pageResult.setData(findbanner);
        return pageResult;
    }

    @Override
    public R addbannner(Bannerb bannerb) {
        System.out.println("11111111111111111111111111111111111222222222222222222222222222");
        int insert = bannerMapper.insert(bannerb);
        R r = new R();
        r.setCode(200);
        r.setMsg("增加成功");
        return r;
    }

    @Override
    public R updatabanner(String id, String status) {
        UpdateWrapper updateWrapper = new UpdateWrapper();
        Object id1 = updateWrapper.eq("id", id);

        Bannerb bannerb = new Bannerb();
        bannerb.setStatus(Integer.parseInt(status));
        System.out.println("1111111111111111111111111111111111111111111111111111111");
        int update = bannerMapper.update(bannerb, updateWrapper);
        R r = new R();
        r.setCode(200);
        r.setMsg("修改成功");
        return r;

    }

}
